package org.dragon.commons;

/**
 * Author:     Zhao Yan
 * DateTime:   2023/5/17 10:04
 */
import com.github.f4b6a3.ulid.UlidCreator;

import java.util.Random;
import java.util.UUID;

public interface Const {

    // 单位：秒
    int EMAIL_CODE_SEND_INTERVAL = 5;

    // 单位：分钟
    int TEMPORARY_AUTH_DURATION = 10;

    // 单位：分钟
    int AUTHORIZED_DURATION = 24 * 60;

    String ROOT = "root";

    String TOKEN = "token";

    String CONTENT_TYPE = "Content-Type";

    String ACCOUNT = "account";

    String AUTHORIZATION = "Authorization";

    static String uuid() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    static String ulid() {
        return UlidCreator.getUlid().toString();
    }

    static String randomNumberCode(int units) {
        Random random = new Random(System.nanoTime());
        StringBuilder result = new StringBuilder();

        for (int i = 0; i < units; i++)
            result.append(random.nextInt(0, 10));

        return result.toString();
    }

    static String randomEmailCode() {
        return randomNumberCode(5);
    }
}